package com.louis.buddhist.ui.activity;

import android.content.Intent;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.louis.buddhist.R;
import com.louis.buddhist.ui.base.BaseActivity;
import com.louis.buddhist.util.CommonUtil;
import com.louis.buddhist.widget.dialog.CollectDialogFragment;
import com.louis.buddhist.widget.dialog.ReadDialogFragment;

import butterknife.BindView;

public class DisclaimerActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.drawerlayout)
    DrawerLayout mDrawerLayout;
    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.tv_main_page)
    TextView mTvMainPage;
    @BindView(R.id.tv_constacts_us)
    TextView mTvConstactsUs;
    @BindView(R.id.tv_collect)
    TextView mTvCollect;
    @BindView(R.id.tv_read)
    TextView mTvRead;
    @BindView(R.id.tv_disclaimer)
    TextView mTvDisclaimer;
    @BindView(R.id.tv_version)
    TextView mTvVersion;

    @Override
    protected int setContentView() {
        return R.layout.activity_disclaimer;
    }

    @Override
    protected void initView() {
        setSupportActionBar(mToolbar);
        //隐藏toolbar上的title
        getSupportActionBar().setDisplayShowTitleEnabled(false);

        ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close);
        //同步状态
        drawerToggle.syncState();
        //给侧滑控件设置监听
        mDrawerLayout.addDrawerListener(drawerToggle);
    }

    @Override
    protected void initData() {
        mTvMainPage.setOnClickListener(this);
        mTvConstactsUs.setOnClickListener(this);
        mTvDisclaimer.setOnClickListener(this);
        mTvCollect.setOnClickListener(this);
        mTvRead.setOnClickListener(this);
        mToolbar.setOnClickListener(this);
        mTvVersion.setText("版本號：" + CommonUtil.getVersion(this));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_main_page:
            case R.id.toolbar:
                finish();
                break;
            case R.id.tv_constacts_us:
                toContacts();
                break;
            case R.id.tv_disclaimer:
                mDrawerLayout.closeDrawer(Gravity.LEFT);
                break;
            case R.id.tv_collect:
                showCollectList();
                break;
            case R.id.tv_read:
                showReadList();
                break;
        }
    }

    private void toContacts() {
        Intent intent = new Intent(this, ContactsUsActivity.class);
        startActivity(intent);
        finish();
    }

    private void showCollectList() {
        CollectDialogFragment fragment = new CollectDialogFragment();
        fragment.show(getSupportFragmentManager(), "CollectDialogFragment");
        mDrawerLayout.closeDrawer(Gravity.LEFT);
    }

    private void showReadList() {
        ReadDialogFragment fragment = new ReadDialogFragment();
        fragment.show(getSupportFragmentManager(), "ReadDialogFragment");
        mDrawerLayout.closeDrawer(Gravity.LEFT);
    }
}
